package com.cl.edu.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cl.edu.dao.AreaDAO;
import com.cl.edu.dao.CountryDAO;
import com.cl.edu.dao.EducationDAO;
import com.cl.edu.dao.HighschoolDAO;
import com.cl.edu.dao.StatusDAO;
import com.cl.edu.dao.SubjectDAO;
import com.cl.edu.dao.TeacherDAO;
import com.cl.edu.entity.Area;
import com.cl.edu.entity.Country;
import com.cl.edu.entity.Education;
import com.cl.edu.entity.Highschool;
import com.cl.edu.entity.Status;
import com.cl.edu.entity.Subject;
import com.cl.edu.entity.Teacher;

/**
 * 教师注册页面信息处理
 * @author lihx
 *
 */
@Service 
@Transactional
public class RegisterManager {
	@Autowired
	private TeacherDAO teacherDAO;
	@Autowired
	private AreaDAO areaDAO;
	@Autowired
	private HighschoolDAO highschoolDAO;
	@Autowired
	private CountryDAO countryDAO;
	@Autowired
	private StatusDAO statusDAO;
	@Autowired
	private EducationDAO educationDAO;
	@Autowired
	private SubjectDAO subjectDAO;
	
	/**
	 * 检测某教师用户名是否存在
	 * @param name
	 * @return
	 */
	public boolean isExist(String username) {
		return teacherDAO.hasUsername(username);
	}

	/**
	 * 通过id获取教师信息
	 * @param id
	 * @return
	 */
	public Teacher getTeacherById(Long id) {
		return teacherDAO.get(id);
	}
	
	/**
	 * 查询中国所有省级行政区划
	 * @return
	 */
	public List<Area> getSheng() {
		return areaDAO.getSheng();
	}
	
	/**
	 * 查询沈阳市下级行政区划
	 * @return
	 */
	public List<Area> getShenYang() {
		return areaDAO.getShenYang();
	}
	
	/**
	 * 查询所有国家
	 * @return
	 */
	public List<Country> getCountries() {
		return countryDAO.getAll();
	}
	
	/**
	 * 查询所有高校
	 * @return
	 */
	public List<Highschool> getHighschools() {
		return highschoolDAO.getAll();
	}
	
	/**
	 * 按类别查询现在状态
	 * @param status
	 * @return
	 */
	public List<Status> getStatus(Long status) {
		return statusDAO.getListByStatus(status);
	}
	
	/**
	 * 查询学历
	 * @return
	 */
	public List<Education> geteEducations() {
		return educationDAO.getAll();
	}
	
	/**
	 * 获取学科
	 */
	public List<Subject> getSubjects(String position) {
		return subjectDAO.getSubjectsByPosition(position);
	}

	/**
	 * 保存教师注册信息
	 * @param entity
	 */
	public void saveTeacher(Teacher entity) {
		teacherDAO.save(entity);
	}
}
